<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ include file="../common/tags.jsp" %>  
<%
	String path = request.getContextPath();
%>
<script type="text/javascript">
function searchEntityForm(obj) {
	var amountFrom = $("#inp_cardIssueAmountFrom_cardEntitList").val();
	var amountTo = $("#inp_cardIssueAmountTo_cardEntitList").val();
	if (amountFrom != "") {
		amountFrom=checkNum(amountFrom);
		$("#inp_cardIssueAmountFrom_cardEntitList").val(amountFrom);
	}
	if (amountTo != "") {
		amountTo=checkNum(amountTo);
		$("#inp_cardIssueAmountTo_cardEntitList").val(amountTo);
	}
	if(amountFrom!=""&&amountTo!=""){
		if(amountFrom>amountTo){
			alertMsg.error("发卡数范围起始不能大于结束！");
			return false;
		}
	}
	if('${searchType}' == '') {
			return navTabSearch(obj);
		}
	else {
		return dwzSearch(obj, 'dialog');
	}
}
function cardEntityBringBack(cardId,customerId,cardCode,cardName,fileds){
	if(fileds.indexOf("email")>=0){
		parent.document.getElementById("email").style.display="block";
		$("#email_text",window.parent.document).addClass("required email");
	}else if(fileds.indexOf("email")<0){
		parent.document.getElementById("email").style.display="none";
		$("#email_text",window.parent.document).removeClass("required");
	}
	
	if(fileds.indexOf("qq")>=0){
		parent.document.getElementById("qq").style.display="block";
		$("#qq_text",window.parent.document).addClass("required digits");
	}else if(fileds.indexOf("qq")<0){
		parent.document.getElementById("qq").style.display="none";
		$("#qq_text",window.parent.document).removeClass("required");
	}
	
	if(fileds.indexOf("address")>=0){
		parent.document.getElementById("address").style.display="block";
		$("#address_text",window.parent.document).addClass("required");
	}else if(fileds.indexOf("address")<0){
		parent.document.getElementById("address").style.display="none";
		$("#address_text",window.parent.document).removeClass("required");
	}
	if(fileds.indexOf("idcard")>=0){
		parent.document.getElementById("idcard").style.display="block";
		$("#idcard_text",window.parent.document).addClass("required");
	}else if(fileds.indexOf("idcard")<0){
		parent.document.getElementById("idcard").style.display="none";
		$("#idcard_text",window.parent.document).removeClass("required");
	}
	
	if(fileds.indexOf("birthday")>=0){
		parent.document.getElementById("birthday").style.display="block";
		$("#birthday_text",window.parent.document).addClass("required");
	}else if(fileds.indexOf("birthday")<0){
		parent.document.getElementById("birthday").style.display="none";
		$("#birthday_text",window.parent.document).removeClass("required");
	}
	$.bringBack({cardId:cardId,customerId:customerId,cardCode:cardCode, cardName:cardName});
}

</script>
<form id="pagerForm" method="post" action="<%=path %>/cardEntity/listCardEntity.action">
	<input type="hidden" name="pageRequest" value="1" />
	<input type="hidden" name="pageNum" value="${paginator.pageIndex}" />
	<input type="hidden" name="numPerPage" value="${paginator.pageSize}" />
</form>

<div class="pageHeader">
	<form onsubmit="return searchEntityForm(this);" rel="pagerForm" action="<%=path %>/cardEntity/listCardEntity.action" method="post">
	<input type="hidden" name="searchType" value="${searchType}"/>
	<input type="hidden" name="cardEntityVO.custSend" value="${cardEntityVO.custSend}"/>
	<div class="searchBar">
		<ul class="searchContent">
			<li>
				<label style="text-align: right;">会员卡编码：</label>
				<input type="text" name="cardEntityVO.schemeCode" value='<s:property value="cardEntityVO.schemeCode" />' size="20"/>
			</li>
			<li>
			<label style="text-align: right;">会员卡名称：</label>
				<input name="cardEntityVO.cardName" value="<s:property value="cardEntityVO.cardName" />" type="text" size="20" />
			</li>
			<li>
				<label style="text-align: right;">发卡数：</label>
				<input id="inp_cardIssueAmountFrom_cardEntitList" name="cardEntityVO.cardIssueAmountFrom" value="<s:property value="cardEntityVO.cardIssueAmountFrom" />" type="text" size="5" />
				&nbsp;至&nbsp;<input id="inp_cardIssueAmountTo_cardEntitList" name="cardEntityVO.cardIssueAmountTo" value="<s:property value="cardEntityVO.cardIssueAmountTo" />" type="text" size="5" />
			</li>
		</ul>
		<ul class="searchContent">
			<li>
				<input type="hidden" id="list_db_cardEntity_cardLever" value="<s:property value="cardEntityVO.cardLever" />"/>
				<label style="text-align: right;">会员卡级别：</label>
				<select name="cardEntityVO.cardLever" class="combox" id="list_cardEntity_cardLever">
					<option value="-1" >请选择</option>
                    <c:forEach var="item" items="${cardLevelList}">
                        <option value="${item.id}" ${cardEntityVO.cardLever eq item.id?"selected":"" }>${item.levelName}</option>
                    </c:forEach>
				</select>
			</li>
			<li>
				<label style="text-align: right;">申请方式：</label>
				<select name="cardEntityVO.applyWay" class="combox">
					<option value="">请选择</option>
					<option value="1"${cardEntityVO.applyWay==1?" selected='true'":""}>商家自发</option>
					<option value="2"${cardEntityVO.applyWay==2?" selected='true'":""}>商家自发+自主申请</option>
					<option value="3"${cardEntityVO.applyWay==3?" selected='true'":""}>自主申请</option>
				</select>
			</li>
			<c:choose>
				<c:when test="${SESSION_USER.customer==null}">
					<input name="cardEntityVO.customerId" value="${cardEntityVO.customerId}" type="hidden">
					<c:if test="${searchType==null||searchType==''}">
						<li>
							<label style="text-align: right;">所属商家：</label>
							<input name="cardEntityVO.customerName" onclick="$('#cardEntityList_a_btnLook').click();" style="cursor: pointer; float: left" value="<s:property value="cardEntityVO.customerName" />">
							<!-- <a class="btnLook" id="cardEntityList_a_btnLook" href="<%=path%>/customer/listCustomer.action?searchType=active" lookupGroup="cardEntityVO">选择</a> -->
						</li>
					</c:if>
				</c:when>
				<c:otherwise>
					<input name="cardEntityVO.customerId" value="${SESSION_USER.customer.id}" type="hidden">
				</c:otherwise>
			</c:choose>
		</ul>
		<ul class="searchContent">
			<li style="width:450px">
				<label style="text-align: right;">有效期：</label>
				从<input type="text" name="cardEntityVO.expiryDateFrom" class="date" readonly="false" value="<s:date name="cardEntityVO.expiryDateFrom" format="yyyy-MM-dd" />" size="10"/>
				到<input type="text" name="cardEntityVO.expiryDateTo" class="date" readonly="false" value="<s:date name="cardEntityVO.expiryDateTo" format="yyyy-MM-dd" />" size="10"/>
			</li>
		</ul>
		<div class="subBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">查询</button></div></div></li>
			</ul>
		</div>
	</div>
	</form>
</div>
<div class="pageContent">
	<c:if test="${searchType==null|| searchType==''}">
	<div class="panelBar">
		<ul class="toolBar">
			<shiro:hasPermission name="addCardEntity">
			<li><a class="add" href="<%=path %>/cardEntity/addCardEntity.action" target="navTab"><span>添加</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="editCardEntity">
			<li><a class="edit" href="<%=path %>/cardEntity/editCardEntity.action?cardEntityVO.id={sid_user}" target="navTab" warn="请选择一个用户"><span>修改</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="deleteCardEntity">
			<li><a title="确实要删除这些记录吗?" target="selectedTodo" tbName="card_entity" rel="ids" postType="string" href="<%=path %>/cardEntity/deleteCardEntity.action" class="delete"><span>删除</span></a></li>
			</shiro:hasPermission>
		</ul>
	</div>
	</c:if>
	<table class="table" width="1400" layoutH="189">
		<thead>
			<tr>
				<c:if test="${searchType==null|| searchType==''}"><th width="30"><input type="checkbox" group="ids" class="checkboxCtrl"></th></c:if>
				<th>会员卡名</th>
				<th>商户编码</th>
				<th>商户名</th>
				<th>会员卡方案编码</th>
				<th>会员卡级别</th>
				<th>有效期开始</th>
				<th>有效期截止</th>
				<th>申请方式</th>
				<th>基础折扣</th>
				<th>数量限制</th>
				<th>发卡数</th>
				<th>二维码串</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<s:iterator value="cardEntityList" id="cardEntity" status="st">
				<tr target="sid_user" rel="<s:property value="id" />">
					<c:if test="${searchType==null|| searchType==''}">
						<td><input name="ids" value="<s:property value="id" />" type="checkbox"></td>
					</c:if>
					 <td><s:property value="cardName" /></td>	
		             <td><s:property value="merchantCode" /></td>	
		             <td><s:property value="merchantNamer" /></td>	
		             <td><s:property value="schemeCode" /></td>	
		             <td><s:property value="cardLevelVO.levelName" /></td>
					 <td><s:date name="expiryDateFrom" format="yyyy-MM-dd" /></td>
					 <td><s:date name="expiryDateTo" format="yyyy-MM-dd" /></td>
		             <td><c:if test="${cardEntity.applyWay==1}">商家自发</c:if><c:if test="${cardEntity.applyWay==2}">商家自发+自主申请</c:if><c:if test="${cardEntity.applyWay==3}">自主申请</c:if></td>
		             <td><s:property value="cardAgioVO.name" /></td>	
		             <td><s:property value="limitAmount" /></td>
		             <td><s:property value="cardIssueAmount" /></td>
		             <td>1:<s:property value="id" /></td>
		             <c:if test="${searchType==null||searchType==''}">
					 <td>
					 	<shiro:hasPermission name="deleteCardEntity">
						<a title="确实要删除这条记录吗?" target="ajaxTodo" tbName="card_entity" ids="${id}" href="<%=path %>/cardEntity/deleteCardEntity.action?ids=<s:property value="id" />" class="btnDel">删除</a>
						</shiro:hasPermission>
						<shiro:hasPermission name="editCardEntity">
						<a title="编辑" target="navTab" href="<%=path %>/cardEntity/editCardEntity.action?cardEntityVO.id=<s:property value="id" />" class="btnEdit">编辑</a>
						</shiro:hasPermission>
						<a title="查看" target="navTab" href="<%=path%>/cardEntity/viewCardEntity.action?cardEntityVO.id=${id}" class="btnView">查看</a>
					 </td>
					 </c:if>
					<c:if test="${searchType=='sendCard'}">
						<td><a class="btnSelect" href="javascript:cardEntityBringBack('${cardEntity.id}','${cardEntity.customerId}','${cardEntity.schemeCode}','${cardEntity.cardName}','${cardEntity.inputFileds}');" title="查找带回">选择</a>
					</c:if>
					<c:if test="${searchType=='advertising'}">
						<td><a class="btnSelect" href="javascript:$.bringBack({linkId:'${id}', cardName:'${cardName}'});" title="查找带回">选择</a>
					</c:if>
				</tr>
			</s:iterator>
		</tbody>
	</table>
	<div class="panelBar">
		<div class="pages">
				<span>显示</span>
				<select class="combox" name="numPerPage" onchange='<s:if test="%{searchType==null||searchType==''}">navTabPageBreak({numPerPage:this.value})</s:if><s:else>dialogPageBreak({numPerPage:this.value})</s:else>'>
					<option value="15" <c:if test="${paginator.pageSize==15}">selected='selected'</c:if> >15</option>
					<option value="30" <c:if test="${paginator.pageSize==30}">selected='selected'</c:if> >30</option>
					<option value="50" <c:if test="${paginator.pageSize==50}">selected='selected'</c:if> >50</option>
					<option value="100" <c:if test="${paginator.pageSize==100}">selected='selected'</c:if> >100</option>
					<option value="200" <c:if test="${paginator.pageSize==200}">selected='selected'</c:if> >200</option>
				</select>
				<span>条，共${paginator.totalCount}条</span>
			</div>
			<div class="pagination" targetType="${(searchType==null||searchType=='')?'navTab':'dialog'}" totalCount="${paginator.totalCount}" 
				numPerPage="${paginator.pageSize}" pageNumShown="10" currentPage="${paginator.pageIndex}"></div>
	</div>
</div>
